@extends('users.app')
@section('title', '站点列表')
@section('content')
<div class="row">
    <div class="col-12 col-xl-10 m-b-10">
    <div class="card">
        <div class="card-header border-bottom">
            <h4 class="card-title">站点列表</h4>
        </div>
        <div class="card-body">
            <div class="row">
            <div class="col-sm-10 col-md-5">
              <form action="{{ route('sites.index') }}" method="GET">
              <div class="form-group">
                <div class="input-group">
                  <input class="form-control" type="text" name="title" value="{{ old('title', Request::input('title') ?: '')}}" placeholder="输入站点标题">
                  <div class="input-group-append">
                    <button class="btn btn-info" type="submit">搜索</button>
                  </div>
                </div>
              </div>
              </form>
            </div>
            @if ($user->hasRole('Founder'))
            <div class="col-sm-10 col-md-5">
              <form action="{{ route('sites.index') }}" method="GET">
              <div class="form-group">
                <div class="input-group">
                  <input class="form-control" type="text" name="username" value="{{ old('username', Request::input('username') ?: '')}}" placeholder="输入用户名">
                  <div class="input-group-append">
                    <button class="btn btn-info" type="submit">搜索</button>
                  </div>
                </div>
              </div>
              </form>
            </div>
            @endif
          </div>
            <div class="table-responsive">
                <table class="table table-bordered mb-0">
                    <thead>
                        <tr>@if ($user->hasRole('Founder'))
                            <th>编号</th>
                            @endif
                            <th>站点标题</th>
                            @if($user->hasRole('Founder'))
                            <th>用户</th>
                            @endif
                            <th>添加时间</th>
                            <th>最后修改时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($sites as $site)
                        <tr>@if ($user->hasRole('Founder'))
                            <th scope="row">{{$site->id}}</th>
                            @endif
                            <td><a href="{{ route('sites.edit', ['site' => $site->id]) }}">{{$site->title}}</a></td>
                            @if($user->hasRole('Founder'))
                            <td>
                              <a href="{{ route('sites.member', $site->user->id) }}">{{$site->user->name}}</a>
                            </td>
                            @endif
                            <td>{{ $site->created_at->diffForHumans() }}</td>
                            <td>{{ $site->updated_at->diffForHumans() }}</td>
                            <td>
                              @can('destroy', $site)
                                <a href="{{ route('sites.edit', $site->id)}}" class="btn btn-sm btn-danger mt-2">编辑</a>
                                <form action="{{ route('sites.destroy', $site->id) }}" method="POST" class="" style="display: inline;" onsubmit="return confirm('Delete? Are you sure?');">
                                  {{csrf_field()}}
                                  <input type="hidden" name="_method" value="DELETE">

                                  <button type="submit" class="btn btn-sm btn-danger mt-2">删除</button>
                                </form>
                                <a href="{{ route('short_urls.show', ['site' => $site->id, 'type' => 2]) }}" class="btn btn-sm btn-common mt-2">随机视频推广</a>
                                <a href="{{ route('short_urls.show', ['site' => $site->id, 'type' => 1]) }}" class="btn btn-sm btn-common mt-2">固定视频推广</a>
                              @endcan
                            </td>
                        </tr>
                        @endforeach
                    </tbody>
                </table>
                <div class="mt-2">
                  {!! $sites->appends(Request::except('page'))->render() !!}
                </div>
            </div>
        </div>
      </div>
    </div>
</div>
@stop
